FROM centos:7.2.1511 as java-build
MAINTAINER biebbwa@163.com
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    cd /etc/pki/rpm-gpg && \
    curl -O http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 && \
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \
    rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm && \
    rpm --rebuilddb && yum install -y git unzip maven java-1.8.0-openjdk*

WORKDIR /home
#设置maven 阿里云镜像
COPY ./maven/config/settings.xml /etc/maven

RUN git clone https://gitee.com/macrozheng/mall.git && \
    cd /home/mall && \
    mvn package && \
    cd /home && \
    git clone https://gitee.com/macrozheng/mall-admin-web.git




############## mysql 服务 #####################
FROM mysql:5.7.26 as mysql
RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
    mkdir -p /opt/sql
COPY ./mysql/init/init.sql /docker-entrypoint-initdb.d/
COPY --from=java-build /home/mall/document/sql/mall.sql /opt/sql/mall.sql
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/ && \
    chown -R mysql:mysql /opt/sql/


############## mall-admin-web 服务 #####################
FROM node:12.14 as mall-admin-web
ENV TZ=Asia/Shanghai
ENV MODULE_NAME mall-admin-web
COPY wait-for-it.sh /usr/local/bin
RUN  mkdir -p /app && \
     chmod +x /usr/local/bin/wait-for-it.sh && \
     ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
     npm config set registry http://registry.npm.taobao.org

COPY --from=java-build /home/${MODULE_NAME} /app
WORKDIR /app
RUN npm install
EXPOSE 8090
ENTRYPOINT wait-for-it.sh  mall-admin:8080 -s -t 0 --  npm run dev

############## mall-admin 服务 #####################
FROM openjdk:8 as mall-admin
ENV TZ=Asia/Shanghai
ENV MODULE_NAME mall-admin
ENV JAVA_OPT --spring.profiles.active=prod --spring.datasource.url=jdbc:mysql://db:3306/mall?useSSL=false&useUnicode=true&characterEncoding=utf-8&useLegacyDatetimeCode=false&serverTimezone=${TZ}
COPY wait-for-it.sh /usr/local/bin
RUN  mkdir -p /app && \
     chmod +x /usr/local/bin/wait-for-it.sh && \
     ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY --from=java-build /home/mall/${MODULE_NAME}/target/${MODULE_NAME}-1.0-SNAPSHOT.jar /app/app.jar
WORKDIR /app
EXPOSE 8080
ENTRYPOINT wait-for-it.sh  logstash:4560 -s -t 0 -- java  -jar app.jar ${JAVA_OPT}

############## mall-search 服务 #####################
FROM openjdk:8 as mall-search
ENV TZ=Asia/Shanghai
ENV MODULE_NAME mall-search
ENV JAVA_OPT --spring.profiles.active=prod --spring.datasource.url=jdbc:mysql://db:3306/mall?useSSL=false&useUnicode=true&characterEncoding=utf-8&useLegacyDatetimeCode=false&serverTimezone=${TZ}
COPY wait-for-it.sh /usr/local/bin
RUN  mkdir -p /app && \
     chmod +x /usr/local/bin/wait-for-it.sh && \
     ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY --from=java-build /home/mall/${MODULE_NAME}/target/${MODULE_NAME}-1.0-SNAPSHOT.jar /app/app.jar
WORKDIR /app
EXPOSE 8081
ENTRYPOINT wait-for-it.sh  mall-admin:8080 -s -t 0 -- java  -jar app.jar ${JAVA_OPT}

############## mall-portal 服务 #####################
FROM openjdk:8 as mall-portal
ENV TZ=Asia/Shanghai
ENV MODULE_NAME mall-portal
ENV JAVA_OPT --spring.profiles.active=prod --spring.datasource.url=jdbc:mysql://db:3306/mall?useSSL=false&useUnicode=true&characterEncoding=utf-8&useLegacyDatetimeCode=false&serverTimezone=${TZ}
COPY wait-for-it.sh /usr/local/bin
RUN  mkdir -p /app && \
     chmod +x /usr/local/bin/wait-for-it.sh && \
     ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY --from=java-build /home/mall/${MODULE_NAME}/target/${MODULE_NAME}-1.0-SNAPSHOT.jar /app/app.jar
WORKDIR /app
EXPOSE 8085
ENTRYPOINT wait-for-it.sh  mall-search:8081 -s -t 0 -- java  -jar app.jar ${JAVA_OPT}


############## elasticsearch #####################
FROM elasticsearch:7.6.2 as elasticsearch
ADD ./elk/ik/ik.tar.gz /usr/share/elasticsearch/plugins

############## logstash ###########################
FROM logstash:7.6.2 as logstash
RUN /usr/share/logstash/bin/logstash-plugin install logstash-codec-json_lines



